﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Wsitech.BLL;
using Wsitech.Model;

public partial class Backend_SiteMapAdd : BackendPageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request["pid"] != null)
            {
                Wsitech.Model.SiteMapInfo map = SiteMapInfoBLL.Instance.GetDetail(Request["pid"]);
                if (map != null)
                {
                    lbParentSiteMap.Text = map.SitemapName;
                }
            }
            if (Request["sid"] != null)
            {
                initSiteMap(Request["sid"]);
            }
        }
    }

    private void initSiteMap(string siteMapId)
    {
        Wsitech.Model.SiteMapInfo map = SiteMapInfoBLL.Instance.GetDetail(siteMapId);
        if (map != null)
        {
            txtSiteMapName.Text = map.SitemapName;
            txtFrontUrl.Text = map.FrontUrl;
            txtBackUrl.Text = map.BackUrl;


            lbParentSiteMap.Text = SiteMapInfoBLL.Instance.GetSiteMapName(map.ParentId);
        }
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (Request["sid"] != null)
        {
            Wsitech.Model.SiteMapInfo map = SiteMapInfoBLL.Instance.GetDetail(Request["sid"]);
            map.SitemapName = txtSiteMapName.Text.Trim();
            map.FrontUrl = txtFrontUrl.Text.Trim();
            map.BackUrl = txtBackUrl.Text.Trim();

            SiteMapInfoBLL.Instance.Update(map);
            //Response.Redirect(Request.Path);
        }
        else
        {
            SiteMapInfoBLL.Instance.AddSiteMap(Request["pid"] ?? "", txtSiteMapName.Text.Trim(), txtFrontUrl.Text.Trim(), txtBackUrl.Text.Trim());
            //Response.Redirect(Request.Url.ToString());
        }
        base.RefreshParent();
    }
}